Page({
  data: {
    beginFocus:false,
    endFocus:false,
    beginDate:null,
    endDate:null,
    totalMoney:0, //总额
    assistMoney:0,  //协助金额
    array: [], //画稿收款记录
  
  },
  onLoad(){
   
  },
  onShow(){
    let token = my.getStorageSync({ key: 'token' }).data;
    if(token == null){
      my.confirm({
      title: '温馨提示',
      content: '当前还未登录：是否需要登录？',
      confirmButtonText: '马上登录',
      cancelButtonText: '暂不需要',
      success: (result) => {
        if(result.confirm){
            //登录
            my.redirectTo({
             url: '/pages/common/login/login'
            })
        }else{
          //暂不登录
           my.switchTab({
             url: '/pages/user/user'
            })
        }
        },
      });
      return false;
    }
    //查询全部记录
    this.getList(this.data.beginDate?this.data.beginDate:null,this.data.endDate?this.data.endDate:null,token);
  },
  getList(beginTime,endTime,token){
      let that = this;
      my.showLoading({
        content: '加载中...'
      });
        //请求数据
      my.request({
      url: 'https://tiyi.site/seaHorse/app/drawAuth/getDrawCashList',
      method: 'POST',
      headers: 
      {
       'content-type': 'application/json',
       'token':token
      },
      data: {
        beginTime:beginTime,
        endTime:endTime
      },
      dataType: 'json',
      success: function(res) {
       
        if(res.data.code == 0){
          that.setData({
            array:res.data.list,
            totalMoney:res.data.totalMoney,
            assistMoney:res.data.assistMoney
          })
        }else if(res.data.code == 401){
            //去登录
            my.redirectTo({
              url: '/pages/common/login/login'
            }) 
        }
      },
      fail: function(res) {
        my.alert({content: res});
      },
      complete: function(res) {
        my.hideLoading();
      }
      });
  },
  onItemClick(ev) {

    my.navigateTo({
     url: '/pages/detail/detail?drawId='+ev.target.dataset.id
    })
  },
  onBeginFocus() {
    this.setData({
      focus: true,
    });
    my.datePicker({
      currentDate: '2019-08-01',
      startDate: '2019-01-01',
      endDate: '2020-10-10',
      success: (res) => {

        this.setData({
          beginDate: res.date,
        });
         //回调成功 自动查询
        this.getList(res.date,this.data.endDate);
      },
    });

  },
  onBeginBlur() {
    this.setData({
      focus: false,
    });
    
  },
  onEndFocus() {
    this.setData({
      focus: true,
    });
    my.datePicker({
      currentDate: this.data.beginDate?this.data.beginDate:'2019-08-01',
      startDate: '2019-01-01',
      endDate: '2020-10-10',
      success: (res) => {
          this.setData({
            endDate: res.date,
          });
          //回调成功 自动查询
          this.getList(this.data.beginDate,res.date);
      },
    });

    },
  onEndBlur() {
    this.setData({
      focus: false,
    });

  },

  onScrollToLower() {
 
    // my.setBackgroundTextStyle({
    // textStyle: 'dark', // 下拉背景字体、loading 图的样式为dark
    // })
    // const { items5 } = this.data;
    // const newItems = items5.concat(newitems);
    // console.log(newItems.length);
    // this.setData({
    //   items5: newItems,
    // });
  },
});
